<?php
	get_header();
?>

<main id="content" role="main">

<?php if(is_search()) : ?>
	<header class="page-header<?php echo $wp_query->found_posts ? ' result' : ' nofind'; ?>">
		<h1>搜索《<?php echo get_search_query(); ?>》的结果</h1>
		<p class="search-result">共找到<?php echo $wp_query->found_posts; ?>条记录<br>对结果不满意？重新输入关键词搜索：</p>
		<?php get_search_form(true); ?>
	</header>
<?php endif; ?>

<?php if(is_archive()) : ?>
	<header class="page-header">
		<h1><?php the_archive_title(); ?></h1>
		<p class="excerpt"><?php echo wp_strip_all_tags(get_the_archive_description()); ?></p>
	</header>
<?php endif; ?>

<?php 
	$count = 0;
	while(have_posts()) : the_post();
	$count++;
	if($count == 4) {
		dynamic_sidebar('inloop');
	}
?>

	<article class="entry">
		<header class="entry-header">
			<h1><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title_attribute(); ?></a></h1>
		</header>

		<footer class="entry-meta">
			<span class="category"><?php the_category(' ', ''); ?></span>
			<?php
				if(!wp_is_mobile()) {
					the_tags('<span class="tags">', ', ', '</span>');
				}
			?>
			<time datetime="<?php the_time('c'); ?>" pubdate><?php the_time(get_option('date_format')); ?></time>
			<span class="views"><?php lite_post_views(); ?></span>
		</footer>

		<p class="excerpt">
			<?php
				echo mb_strimwidth(wp_strip_all_tags($post->post_content, true), 0, 280, '...' );
			?>
		</p>
		<p class="more-link"><a class="btn" href="<?php the_permalink(); ?>">阅读全文</a></p>
	</article>

<?php 
	endwhile;

	$post_pagination = paginate_links(array(
		'type' => 'list',
		'prev_text' => '&laquo;',
		'next_text' => '&raquo;',
	));

	if($post_pagination) {
		echo '<nav class="post-pagination" role="navigation">' . $post_pagination . '</nav>';
	}

	wp_reset_query();
?>

</main>

<?php
	get_footer();
?>